package com.lw.sbdemo2;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ArrayUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.Banner;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;

import javax.servlet.MultipartConfigElement;
import java.lang.invoke.MethodHandles;
import java.util.Arrays;

/**
 * <p>标题: SpringBoot模板项目启动类</p>
 * <p>描述: </p>
 * <p>版权: Copyright (c) 2018</p>
 * <p>公司: 山人行工作室</p>
 *
 * @author: LinWang
 * @date 2018-6-10
 */
@SpringBootApplication
@Slf4j
public class Sbdemo3Application {

    private final static Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

    public static void main(String[] args) {

        SpringApplication application = new SpringApplication(Sbdemo3Application.class);
        application.setBannerMode(Banner.Mode.OFF);
        args = ArrayUtils.add(args, "LinWang");
        application.run(args);
        logger.info(" SpringBoot模板项目启动完毕");
    }

    @Bean
    public CommandLineRunner runner() {
        return args -> log.info("程序加载完毕，参数：{}", Arrays.toString(args));
    }

    /**
     * 文件上传配置
     *
     * @return
     */
    @Bean
    public MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory factory = new MultipartConfigFactory();
        //单个文件最大
        factory.setMaxFileSize("100MB"); //KB,MB
        //设置总上传数据总大小
        factory.setMaxRequestSize("100MB");
        return factory.createMultipartConfig();
    }
}
